//
//  WebViewOfCommendViewController.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/1.
//  Copyright © 2016年 KX. All rights reserved.
//

#import "WebViewOfCommendViewController.h"
#import "FreeTravelMacro.h"
#import "UMSocial.h"
@interface WebViewOfCommendViewController ()<UIWebViewDelegate,UMSocialUIDelegate>

@end

@implementation WebViewOfCommendViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    webView.delegate = self;
   
    [self.view addSubview:webView];
    NSURL *url = [NSURL URLWithString:[self.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];

    
    

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"sdfasadfas"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    UIButton *share = [UIButton buttonWithType:UIButtonTypeCustom];
    share.frame = CGRectMake(0, SCREEN_HEIGHT-108, SCREEN_WIDTH, 44);
    
    [self.view addSubview:share];
    [share addTarget:self action:@selector(goShare) forControlEvents:UIControlEventTouchUpInside];
    share.backgroundColor = [UIColor blackColor];
    share.alpha = 0.8;
    [share setTitle:@"分享" forState:UIControlStateNormal];
    [share setTitleColor:COLORFORFREETRAVEL forState:UIControlStateNormal];
    
}
- (void)setUrl:(NSString *)url{
    _url = url;
    
}
- (void)goShare{
  
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"571ecd2ce0f55a510f001589"
                                      shareText:@"a"
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToRenren,UMShareToSina,UMShareToDouban,UMShareToSina,UMShareToTencent,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite,UMShareToAlipaySession,UMShareToQQ,nil]
                                       delegate:nil];

}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}
- (void)goBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('drains-app mGuideToAppBox')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('xd-list fix')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('xdetail-header')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('head-userinfo fix')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('bssDetTit jscmd')[0].style.display = 'none'"];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('prb js_show_reply active')[0].style.display = 'none'"];
   
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('clearfix')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('qui-footerBasic')[0].style.display = 'none'"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.getElementsByClassName('qui-header')[0].style.display = 'none'"];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
